package com.hiwhitley.easy.day09;

/**
 * Created by hiwhitley on 2016/8/13.
 */
public class MajorityElement {
    public int majorityElement(int[] nums) {
        int majority = nums[0], count = 1;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] == majority) count++;
            else if (--count == 0) {
                majority = nums[i];
                count = 1;
            }
        }
        return majority;
    }
}
